//app.js
App({
  data:{
    code:''
  },
  editTabBar: function () {
    //  console.log(';2222')
    var _curPageArr = getCurrentPages();
    var _curPage = _curPageArr[_curPageArr.length - 1];
    var _pagePath = _curPage.__route__;
    
    if (_pagePath.indexOf('/') != 0) {
      _pagePath = '/' + _pagePath;
    }
    var tabBar = this.globalData.tabBar;
    var tabBar2 = this.globalData.tabBar2;
    
    // console.log(_pagePath)
    for (var i = 0; i < tabBar.list.length; i++) {
     
      tabBar.list[i].active = false;
      tabBar2.list[i].active = false;
      
      if (tabBar.list[i].pagePath == _pagePath) {
        
        tabBar.list[i].active = true;//根据页面地址设置当前页面状态    
      }
      if (tabBar2.list[i].pagePath == _pagePath) {

        tabBar2.list[i].active = true;//根据页面地址设置当前页面状态    
      }
    }
    
    this.globalData.tabBar = tabBar
    this.globalData.tabBar2 = tabBar2
   
  },
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // console.log(res)
        this.data.code = res.code
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo
              
              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })
    // var that=this
    // wx.getStorage({//获取本地缓存
    //   key: "apply1",
    //   success: function (res) {
    //     token = res.data
    //       console.log(res.data)
    //     that.globalData.token = res.data
    //     this.setData({
    //       token: res.data
    //     });
    //   },
    // })
    
  },
  
  globalData: {
    userInfo: null,
    api:'url',
    token:'bd18117c97dd11e9b00400163e0a17c1',
    tabBar: {
      "color": "#9E9E9E",
      "selectedColor": "#f00",
      "backgroundColor": "#fff",
      "borderStyle": "#ccc",
      "list": [
        {
          "pagePath": "/pages/index/index",
          "text": "首页",
          "iconPath": "/assets/image/index.png",
          "selectedIconPath": "/assets/image/index-active.png",
          "clas": "menu-item",
          "selectedColor": "#4EDF80",
          'active': true,
          "name":'index'
        },
        {
          "pagePath": "/pages/shop/report/report",
          "text": "报表",
          "iconPath": "/assets/image/subject.png",
          "selectedIconPath": "/assets/image/subject-active.png",
          "selectedColor": "#4EDF80",
          "clas": "menu-item",
          'active': false,
          "name": 'report'
        },
        {
          "pagePath": "/pages/shop/audit/audit",
          "text": "审核",
          "iconPath": "/assets/image/subject.png",
          "selectedIconPath": "/assets/image/subject-active.png",
          "selectedColor": "#4EDF80",
          "clas": "menu-item",
          'active': false,
          "name": 'audit'
        },
        {
          "pagePath": "/pages/shop/mine/mine",
          "text": "我的",         
          "iconPath": "/assets/image/user.png",
          "selectedIconPath": "/assets/image/user-active.png",
          "clas": "menu-item",
          "selectedColor": "#4EDF80",
          'active': false,
          "name": 'mine'
        }
      ],
      "position": "bottom"
    },
    tabBar2: {
      "color": "#9E9E9E",
      "selectedColor": "#f00",
      "backgroundColor": "#fff",
      "borderStyle": "#ccc",
      "list": [
        {
          "pagePath": "/pages/indexmd/indexmd",
          "text": "首页",
          "iconPath": "/assets/image/index.png",
          "selectedIconPath": "/assets/image/index-active.png",
          "clas": "menu-item2",
          "selectedColor": "#4EDF80",
          'active': true,
          "name":"indexmd"
        },
        {
          "pagePath": "/pages/data/data",
          "text": "报表",
          "iconPath": "/assets/image/subject.png",
          "selectedIconPath": "/assets/image/subject-active.png",
          "selectedColor": "#4EDF80",
          "clas": "menu-item2",
          'active': false,
          "name":'data1'
        },
        {
          "pagePath": "/pages/index1/index1",
          "text": "审核",
          "iconPath": "/assets/image/subject.png",
          "selectedIconPath": "/assets/image/subject-active.png",
          "selectedColor": "#4EDF80",
          "clas": "menu-item2",
          'active': false,
          "name": 'index1'
        },
        {
          "pagePath": "/pages/my/my",
          "text": "我的",
          "iconPath": "/assets/image/user.png",
          "selectedIconPath": "/assets/image/user-active.png",
          "selectedColor": "#4EDF80",
          "clas": "menu-item2",
          'active': false,
          "name": 'my'
        }
      ],
      "position": "bottom"

    }
  }
})